package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.player.RechargeModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class TenDayDiscountMallLimit extends BaseActivityMallLimit {

    public TenDayDiscountMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.RechargeActivity.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {

        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {

        //先去检查condition能不能买
        String extendParam = mallInfo.getExtendParam();
        List<Integer> paramList = StringUtils.stringToIntegerList(extendParam, "\\|");
        //如果配置有问题 不给买
        if (paramList.size() != 3) {
            return GameErrorCode.E_MALL_CONFIG_ERROR;
        }
        int buyType = paramList.get(0);         //购买类型 0为单独购买 1为打包购买
        int mallLevel = paramList.get(1);             //购买等级 1 3 6 元
        int day = paramList.get(2);                 //第几天
        //检测购买条件
        int check;
        if (buyType == 0){          //如果是单独购买
            check = player.getModule(RechargeModule.class).checkCanSeparatelyBuyTenDayDiscountMall(activityInfo.getActivityId(), day, mallLevel);
        }else {
            check = player.getModule(RechargeModule.class).checkCanBuyPackageTenDayDisCountMall(activityInfo.getActivityId());
        }
        if (check!=0){
            return check;
        }
        return 0;
    }

    @Override
    protected int activityCheck() {
        if(!ActivityMgr.activityInTime(activityInfo)){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        if(activityInfo.getType() != eActivityType.RechargeActivity.getValue()){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }
}
